package com.zhenghaijin.playbackservice.controller;

import com.zhenghaijin.playbackservice.model.PlaybackRecord;
import com.zhenghaijin.playbackservice.service.PlaybackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/playback")
public class PlaybackController {
    @Autowired
    private PlaybackService playbackService;

    @GetMapping("/{userId}")
    public List<PlaybackRecord> getPlaybackRecords(@PathVariable Long userId) {
        return playbackService.getPlaybackRecordsByUserId(userId);
    }

    @PostMapping
    public void addPlaybackRecord(@RequestBody PlaybackRecord record) {
        playbackService.addPlaybackRecord(record);
    }

    @PutMapping("/{id}")
    public void updatePlaybackRecord(@PathVariable Long id, @RequestBody PlaybackRecord record) {
        record.setId(id);
        playbackService.updatePlaybackRecord(record);
    }

    @DeleteMapping("/{id}")
    public void deletePlaybackRecord(@PathVariable Long id) {
        playbackService.deletePlaybackRecord(id);
    }
}
